/*
 temporary File .. < CImage class Backup  >
 



void CImage::getData(unsigned char* data)
{
		for(int i=0;i<ImageInfo.size ;i+=4)
		{
			data[i]=ImageInfo.data[i];
			data[i+1]=ImageInfo.data[i+1];
			data[i+2]=ImageInfo.data[i+2];
			data[i+3]=ImageInfo.data[i+3];
if(i<100)
{
   std::cout<<" rImg "<<(int)ImageInfo.data[i]<<"\t"<<" g "<<(int)ImageInfo.data[i+1]<<"\t"
	" b "<<(int)ImageInfo.data[i+2]<<" a "<<(int)ImageInfo.data[i+3]<<std::endl;
}


int CImage::getBPP()//Byte Per Pixel
{
	if(error != age::errors::AGE_NO_ERROR)
		return 0;
	return ImageInfo.BPP;
 }

int CImage::getWidth() 
{
	if(error != age::errors::AGE_NO_ERROR)
		return 0;
	return ImageInfo.width ;
}
int CImage::getHeight() 
{
	if(error != age::errors::AGE_NO_ERROR)
		return 0;
	return ImageInfo.height ;
}
int CImage::getFormat()
{
	if(error != age::errors::AGE_NO_ERROR)
		return 0;
	return age::kernal::AGE_RGBA;
}
unsigned char* CImage::getData()
{
	if(error != age::errors::AGE_NO_ERROR)
		return 0;
// return the referance .. not a copy of data 
	return ImageInfo.data;
}
char* CImage::getName()
{
	
	if(error != age::errors::AGE_NO_ERROR)
		return 0;
	return ImageInfo.imageName;
}



--------============----------------
#include "CImage.h"
#   pragma comment (lib, "../IL/DevIL.lib")    
#   pragma comment (lib, "../IL/ILU.lib")        
#   pragma comment (lib, "../IL/ILUT.lib")      


#include"windows.h" 
#include "../IL/il.h"
#include "../IL/ilu.h"
#include "../IL/ilut.h"
#include <iostream>
namespace age
{
	namespace kernal
	{


CImage::CImage(char *fileName)
{
	ImageInfo.width=0;
	ImageInfo.height=0;
	ImageInfo.BPP=0;
	ImageInfo.ImageFormat=(EImageFormat)0;
	ImageInfo.size=0;
	ImageInfo.imageName=new char[255] ;
	ImageInfo.data=0;
	error=age::errors::AGE_NO_ERROR;
	this->hasCKey=false;
//	initialize();
	if(load(fileName) != 1)
		free();
 }
CImage::~CImage()
{
	free();
}

void CImage::initialize()
{
	//initialize DevIL Library
	ilInit();
	iluInit();
	ilutRenderer(ILUT_OPENGL); 
	ilEnable(IL_ORIGIN_SET);
	ilSetInteger(IL_ORIGIN_MODE, IL_ORIGIN_LOWER_LEFT);


	

}
		
int CImage::load(char *fileName)
{
	ilGenImages(1, &image);   
	ilBindImage(image);  

 	if(!ilLoadImage(fileName))
	{
		
		free();
		switch(ilGetError())
		{
		case IL_NO_ERROR : // inaccessible case ..
			{
				error=age::errors::AGE_NO_ERROR;
				return age::errors::AGE_NO_ERROR ;
			}
		case IL_COULD_NOT_OPEN_FILE:
			{
			error=age::errors::AGE_COULD_NOT_OPEN_FILE;
			return age::errors::AGE_COULD_NOT_OPEN_FILE;
			}
		case IL_INVALID_EXTENSION :
			{
			error=age::errors::AGE_INVALID_EXTENSION;
			return age::errors::AGE_INVALID_EXTENSION;
			}
		default :
			{
			error=age::errors::AGE_INTERNAL_ERROR;
			return age::errors::AGE_INTERNAL_ERROR; 
			}
		//	return ilGetError();
		}
	}

	ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE );
	/*if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE ))
	{
			if(ilGetError()==IL_OUT_FORMAT_SAME )
				break;
			free();
			return -1;
	}*/

 
	// image information .
	ImageInfo.imageName = fileName;
	ImageInfo.ImageFormat = age::kernal::AGE_RGBA;
	ImageInfo.width = ilGetInteger(IL_IMAGE_WIDTH);
	ImageInfo.height= ilGetInteger(IL_IMAGE_HEIGHT);
	ImageInfo.BPP   = ilGetInteger(IL_IMAGE_BPP);
	ImageInfo.size =(ImageInfo.width * ImageInfo.height * ImageInfo.BPP);
	//ImageInfo.size = ilGetInteger(IL_IMAGE_SIZE_OF_DATA);
	ImageInfo.data   = new unsigned char[ImageInfo.size];
//	unsigned char*temp=new unsigned char[ImageInfo.size];
	//ImageInfo.data= ilGetData();
	ilCopyPixels(0,0,0,ImageInfo.width,ImageInfo.height,1,IL_RGBA,IL_UNSIGNED_BYTE,ImageInfo.data);

	error=age::errors::AGE_NO_ERROR ;
	return age::errors::AGE_NO_ERROR ; // ok 
}

void CImage::free()
{
	if(ImageInfo.data)
	{
		delete []ImageInfo.data;
		ImageInfo.data=0;
	}
	if(ImageInfo.imageName)
	{
		delete []ImageInfo.imageName;
		ImageInfo.imageName=0;
	}
	ilDeleteImages(1,&image);
}

int CImage::getError()
{
	return error;
}

age::kernal::Color& CImage::getColorKey()
{
	return colorKey ;
}
bool CImage::hasColorKey()
{
	return this->hasCKey;
}
void CImage::generateColorKey(age::kernal::Color color)
{
	//if(ImageInfo.ImageFormat != age::kernal::AGE_RGBA)
		// convert to rgba 
	unsigned char* newData=new unsigned char[ ImageInfo.size];
	for(int i=0;i<ImageInfo.size;i+=4)
	{
		newData[i]= ImageInfo.data[i];
		newData[i+1]= ImageInfo.data[i+1];
		newData[i+2]= ImageInfo.data[i+2];
		if(ImageInfo.data[i] == color.red && ImageInfo.data[i+1] == color.green && ImageInfo.data[i+2] == color.blue )
			newData[i+3] = 0;
		else newData[i+3] = 255 ;
	}
	
	// copy
	for(int i=0;i<ImageInfo.size;i+=4)
	{
		ImageInfo.data[i]=newData[i];
		ImageInfo.data[i+1]=newData[i+1];
		ImageInfo.data[i+2]=newData[i+2];
		ImageInfo.data[i+3]=newData[i+3];
	//	std::cout<<" r "<<(int)ImageInfo.data[i]<<"\t"<<" g "<<(int)ImageInfo.data[i+1]<<"\t"
	//	" b "<<(int)ImageInfo.data[i+2]<<" a "<<(int)ImageInfo.data[i+3]<<std::endl;
	}

	delete []newData ; 
	newData=0;
	hasCKey=true ;
	colorKey = color ;


}

	}

}


			

		
-----

#include"ageMath.h"
#include"COpenGLTexture.h"
#include"COpenGLRender.h"
#include<iostream>

// add these functions :
// 1- Update 
// 2- Sphere Mapping
// 3- helper function ( to be sure that all thing is all right )
namespace age
{
	enum ERender { AGE_OPENGL_SDL ,AGE_OPENGL_WIN32API};
	namespace render
	{

bool COpenGLTexture::createTexture(age::kernal::CImage img,bool mipMaps )
	{
	//	if(!age::math::ispow2(img.getWidth()))
		{
	//		this->textureWidth = age::math::nextPowerOf2(img.getWidth());
		}
	//	else
		{
	//	this->textureHeight =img.getHeight();
		}
	//			if(!age::math::ispow2(img.getHeight()))
		{
//			this->textureHeight = age::math::nextPowerOf2(img.getHeight());
		}
//		else
		{
//			this->textureHeight =img.getHeight();
		}

		//unsigned char*data=new unsigned char[img.ImageInfo.size];
		//img.getData(data);
		//img.ImageInfo.size
		//for(int i=0;i<1000;i+=4)
		{
		//std::cout<<" r "<<(int)data[i]<<"\t"<<" g "<<(int)data[i+1]<<"\t"<<	" b "<<(int)data[i+2]<<" a "<<(int)data[i+3]<<std::endl;
		}
		glGenTextures(1, &textureID);
		glBindTexture(GL_TEXTURE_2D,textureID);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); 
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); 
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

		if(mipMaps == false)
		{//1
			glTexImage2D(GL_TEXTURE_2D, 0, img.ImageInfo.BPP,img.ImageInfo.width , img.ImageInfo.height, 0, img.ImageInfo.ImageFormat, GL_UNSIGNED_BYTE, img.ImageInfo.data);
		this->mipMaps=false;
		return true ;
		}

		else 
		{//2
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); 
		gluBuild2DMipmaps(GL_TEXTURE_2D, img.ImageInfo.BPP,img.ImageInfo.width , img.ImageInfo.height,img.ImageInfo.ImageFormat, GL_UNSIGNED_BYTE, img.ImageInfo.data); 
		this->mipMaps=true;
		return true ;
		}

		//delete []data ;

	return false ; 
	}



//------------------------------------------------------------------

bool COpenGLTexture::isMipMaps() const
	{
	return this->mipMaps;
	}

void COpenGLTexture::deleteTexture()
	{
	glDeleteTextures(1,&textureID);
	}

int COpenGLTexture::getTextureDriverType( )  
	{
		return age::AGE_OPENGL_SDL; 
 		
	}

	}
}

